var Union = function(geometries) {
	this.geometries = geometries;
};

Union.prototype.initialize = function() {
	for(var i in this.geometries) {
		this.geometries[i].initialize();
	}
};

Union.prototype.intersect = function(ray) {
	var minDistance = Infinity;
	var minResult = IntersectResult.noHit;
	for(var i in this.geometries) {
		var result = this.geometries[i].intersect(ray);
		if(result.geometry && result.distance < minDistance){
			minDistance = result.distance;
			minResult = result
		}
	}
	return minResult;
};

var UnionLight = function(lights) {
	this.lights = lights;
};

UnionLight.prototype.initialize  = function() {
	for(var i in this.lights) {
		this.lights[i].initialize();
	}
};

UnionLight.prototype.sample = function(scene, position, normal) {
	var color = Color.black;
	var lightSample;
	for(var i in this.lights) {
		lightSample = this.lights[i].sample(scene, position);
		if(lightSample != LightSample.zero) {
			var NdotL = normal.dot(lightSample.l);
			if(NdotL >= 0){
				color = color.add(lightSample.el.multiply(NdotL));
			}
		}
	}
	return color;
};